package com.hospital.dictionary.module.service.impl;

import com.baomidou.mybatisplus.core.metadata.IPage;
import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import com.hospital.dictionary.module.mapper.StaffDictMapper;
import com.hospital.dictionary.module.entity.StaffDict;
import com.hospital.dictionary.module.service.StaffDictService;
import com.hospital.dictionary.utils.oConvertUtils;
import org.springframework.stereotype.Service;

import javax.annotation.Resource;

/**
 * <p>
 *  服务实现类
 * </p>
 *
 * @author lvyao
 * @since 2022-02-14
 */
@Service
public class StaffDictServiceImpl extends ServiceImpl<StaffDictMapper, StaffDict> implements StaffDictService {

    @Resource
    private StaffDictMapper staffDictMapper;

    @Override
    public IPage<StaffDict> getUserByRoleId(Page<StaffDict> page, String roleId, String username) {
        return staffDictMapper.getUserByRoleId(page,roleId,username);
    }

    @Override
    public boolean resetPassword(String username, String oldPassword, String newPassword, String confirmPassword) {
        StaffDict user = staffDictMapper.getUserByStaffNo(username);
        if(!user.getCmPassword().equals(oldPassword)){
            return false;
        }
        if(oConvertUtils.isEmpty(newPassword)){
            return false;
        }
        if(!newPassword.equals(confirmPassword)){
            return false;
        }
        user.setCmPassword(newPassword);
        int result = this.staffDictMapper.updateById(user);
        return result>0;
    }
}
